using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Woz
{
    /// <summary>
    /// the action that adds a stroke to the screen
    /// </summary>
    internal class AddStrokeAction : Woz.Action
    {
        /// <summary>
        /// default constructor of the add stroke action
        /// </summary>
        /// <param name="pPoints">the points that make up the stroke</param>
        /// <param name="pPen">the pen to draw the stroke with</param>
        public AddStrokeAction(Point[] pPoints, Pen pPen)
        {
            // copy over a reference to the points
            this.mPoints = pPoints;

            // as well as the pen
            this.mPen = pPen;

            // create the woz stroke
            this.mStroke = new Woz.Stroke(this.mPoints, this.mPen);

            // make action string
            this.mActionString = String.Concat("Added ", this.mStroke.ToString());
        }

        /// <summary>
        /// gets the name of the tool this action prefers
        /// </summary>
        public override string ToolName
        {
            get
            {
                return "Pen";
            }
        }

        /// <summary>
        /// gets whether this action can be propagated or not
        /// </summary>
        public override bool Propagatable
        {
            get 
            {
                return true;
            }
        }

        /// <summary>
        /// adds the stroke to the screen manager and current screen
        /// </summary>
        /// <param name="pScreen">the screen to add stroke to</param>
        protected override void OnExecute(Woz.Screen pScreen)
        {
            // add this stroke to the current screen
            pScreen.AddEntity(this.mStroke, true);

            // request an update from the selected screen
            Woz.ScreenManager.Instance.RequestSelectedScreenUpdate(pScreen, this.mStroke.BoundingBox);
        }

        /// <summary>
        /// removes the stroke from the screen manager and current screen
        /// </summary>
        /// <param name="pScreen">the screen to remove stroke from</param>
        protected override void OnUnExecute(Woz.Screen pScreen)
        {
            // remove this stroke from the current screen
            pScreen.RemoveEntity(this.mStroke, true);

            // request an update from the selected screen
            Woz.ScreenManager.Instance.RequestSelectedScreenUpdate(pScreen, this.mStroke.BoundingBox);
        }

        /// <summary>
        /// check to see if this action can be applied to the given screen
        /// </summary>
        /// <param name="pScreen">the screen to check against</param>
        /// <returns>true if the action can be applied to the given screen</returns>
        public override bool CanApplyTo(Woz.Screen pScreen)
        {
            return true;
        }

        /// <summary>
        /// the stroke this action refers to
        /// </summary>
        private Woz.Stroke mStroke;

        /// <summary>
        /// the points that make up the stroke
        /// </summary>
        private Point[] mPoints;

        /// <summary>
        /// the pen to draw the stroke with
        /// </summary>
        private Pen mPen;
    }
}
